package com.sicnustray.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sicnustray.common.Result;
import com.sicnustray.utils.annotation.MyLog;
import com.sicnustray.entity.Feedback;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.sicnustray.service.IFeedbackService;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 十七
 * @since 2022-12-10
 */
@RequiresPermissions("反馈管理")
@RestController
@RequestMapping("/feedback")
public class FeedbackController {
    
        @Resource
        private IFeedbackService feedbackService;

        // 新增或者更新
        @MyLog(value = "新增或更新留言反馈")
        @PostMapping
        public Result save(@RequestBody Feedback feedback) {
                return Result.success(feedbackService.saveOrUpdate(feedback));
                }

        @MyLog(value = "新增留言反馈")
        @PostMapping("/save")
        public Result frontSave(@RequestBody Feedback feedback) {
                        return Result.success(feedbackService.save(feedback));
                }

        @MyLog(value = "单个删除留言反馈")
        @DeleteMapping("/{id}")
        public Result delete(@PathVariable Integer id) {
                return Result.success(feedbackService.removeById(id));
                }

        @MyLog(value = "批量删除留言反馈")
        @PostMapping("/del/batch")
        public Result deleteBatch(@RequestBody List<Integer> ids) {
                return Result.success(feedbackService.removeByIds(ids));
                }

        @MyLog(value = "查询全部留言反馈")
        @GetMapping
        public Result findAll() {
                return Result.success(feedbackService.list());
                }

        @MyLog(value = "查询单个留言反馈")
        @GetMapping("/{id}")
        public Result findOne(@PathVariable Integer id) {
                return Result.success(feedbackService.getById(id));
                }

        @MyLog(value = "分页查询留言反馈")
        @GetMapping("/page")
        public Result findPage(@RequestParam Integer pageNum,
        @RequestParam Integer pageSize,
        @RequestParam (defaultValue = "")String title) {
                QueryWrapper<Feedback> queryWrapper = new QueryWrapper<>();
             //   queryWrapper.orderByDesc("id");
                if(!"".equals(title)){
                        queryWrapper.like("title",title);
                }
                return Result.success(feedbackService.page(new Page<>(pageNum, pageSize), queryWrapper));
                }

        }

